package com.oscar.ehome.utils.view.progressview;


import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.oscar.ehome.R;

/**
 * Created by KID on 2016/11/21.
 * 无网络时显示页面
 */
public class ProgressFrameLayout extends FrameLayout {

    public ProgressFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        init(context);
    }

    public ProgressFrameLayout(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        init(context);
    }

    //    private MyProgressView progressView;
    private LinearLayout no_data_layout;
    private LinearLayout no_network;
    private FrameLayout base_fragment;
    private ImageView img_logo;

    private AgainRequestListener mAgainRequestListener;

    public void setAgainRequestListener(AgainRequestListener listener) {
        mAgainRequestListener = listener;
    }

    public interface AgainRequestListener {
        void againRequest();
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.frame_refresh_layout, this);
        no_data_layout = (LinearLayout) findViewById(R.id.no_data_layout);
        no_network = (LinearLayout) findViewById(R.id.no_network);
        base_fragment = (FrameLayout) findViewById(R.id.base_fragment);
        img_logo = (ImageView) findViewById(R.id.img_logo);

        img_logo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mAgainRequestListener.againRequest();
            }
        });
    }

    public void setLayout(int isNetWork) {
        switch (isNetWork) {
            case 1://无数据
                setNoResult();
                break;
            case 2://无网络
                setLoadFail();
                break;
        }
    }

    public void showRefresh() {// 正在加载
//        progressView.setVisibility(View.VISIBLE);
//        progressView.startprogress();
        no_data_layout.setVisibility(View.GONE);
        no_network.setVisibility(View.GONE);
    }

    public void stopRefresh() {// 加载成功
//        progressView.stopprogress();
//        progressView.setVisibility(View.GONE);
        no_data_layout.setVisibility(View.GONE);
        no_network.setVisibility(View.GONE);
    }

    public void setNoResult() {// 暂无数据  请求失败
//        progressView.stopprogress();
//        progressView.setVisibility(View.GONE);
        no_data_layout.setVisibility(View.VISIBLE);
        no_network.setVisibility(View.GONE);
    }

    public void setLoadFail() {// 网络问题
//        progressView.stopprogress();
//        progressView.setVisibility(View.GONE);
        no_data_layout.setVisibility(View.GONE);
        no_network.setVisibility(View.VISIBLE);
    }


}
